<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Netty WebSocket 时间服务器</title>
</head>
<body>

<script type="text/javascript">

	var socket;
	if(!window.WebSocket)
	{
		window.WebSocket = window.MozWebSocket;	
	}
	
	if(window.WebSocket)
	{
		socket = new WebSocket("ws://localhost:9001/websocket");
		
		socket.onmessage = function(event)
		{
			var ta = document.getElementById('responseText');
			ta.value="";
			alert("message");
			ta.value = event.data;
		};
		
		socket.onopen = function(event)
		{
			var ta = document.getElementById('responseText');
			ta.value = "打开WebSocket服务正常，浏览器支持WebSocket!";
			alert("open");
		};
		
		socket.onclose = function(event)
		{
			var ta = document.getElementById('responseText');
			ta.value="";
			ta.value="WebSocket关闭";
			alert("close");			
		};
	}
	else
	{
		alert('抱歉，您的浏览器不支持WebSocket协议!');
	}
	
	function send(message)
	{
		if(!window.WebSocket)
		{
			return;
		}
		
		alert('当前状态:'+socket.readyState+"；开始状态码:"+WebSocket.OPEN);
		if(socket.readyState == WebSocket.OPEN)
		{
			socket.send(message);
		}
		else
		{
			alert('WebSocket连接没有建立成功！');
		}
	}
	

</script>

<form action="return false">
	<input type="text" name="message" value="Netty最佳实践"/>
	<br/>
	<br/>
	<input type="button"  value="发   送  WebSocket 请  求  消  息"  onclick="send(this.form.message.value)" />
	<hr color="blue"/>
	<h3>服务器返回的应答消息</h3>
	<textarea id="responseText" style="width:500px;height:300px;"></textarea>
</form>
</body>
</html>